<template>
	<view class="goods_item">
		<view class="goods_item__left">
			<radio v-if="showRadioFlag" color="#c00000" :checked="Boolean(goods.goods_state)" @click="radioChange(goods)"></radio>
			<image class="item_left__img" :src="goods.goods_small_logo  || defaultPic"></image>
		</view>
		<view class="goods_item__right">
			<view class="goods_item__name">{{goods.goods_name}}</view>
			<view class="goods_info__box">
				<view class="goods_item__price">￥{{goods.goods_price | toFixedPrice}}</view>
			<uni-number-box v-if="showNumberFlag" class="goods_item__num" :min="1" :value="goods.goods_count" @change="numChangeHandler"></uni-number-box>
			</view>
			
		</view>
	</view>
</template>

<script>
	export default {
		name:"my-goods",
		props: {
			goods: {
				type: Object,
				default: {},
			},
			showRadioFlag: {
				type: Boolean,
				default: false,
			},
			showNumberFlag: {
				type: Boolean,
				default: false,
			},
		},
		data() {
			return {
				defaultPic: 'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png',
			};
		},
		filters: {
			toFixedPrice(numPrice) {
				return Number(numPrice).toFixed(2);
			},
		},
		
		methods: {
			radioChange(goods) {
				this.$emit('radioChange', {
					goods_id: goods.goods_id,
					goods_state: !goods.goods_state,
				});
			},
			
			numChangeHandler(val) {
				this.$emit('numChange', {
					goods_id: this.goods.goods_id,
					goods_count: +val,
				})
			},
		},
	}
</script>

<style lang="scss">
.goods_item {
	width: 750rpx;
	box-sizing: border-box;
		display: flex;
		padding: 10px 5px;
		border-bottom: 1px solid #f0f0f0;
		.goods_item__left {
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-right: 5px;
			.item_left__img {
				width: 100px;
				height: 100px;
				display: block;
			}
		}
		.goods_item__right {
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			.goods_item__name {
				font-size: 12px;
			}
			.goods_info__box {
				display: flex;
				justify-content: space-between;
				.goods_item__price {
					font-size: 16px;
					color: #c00000;
				}
				.goods_item__num {
				}
			}
		}
	}
</style>